home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / pt-exp.h < prev    next >
C/C++ Source or Header  |  1996-11-19  |  9KB  |  421 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_tree_expr2_h)
  24. #define octave_tree_expr2_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. class ostream;
  31.  
  32. class tree_identifier;
  33. class tree_index_expression;
  34. class tree_indirect_ref;
  35. class tree_argument_list;
  36.  
  37. class tree_walker;
  38.  
  39. #include "pt-exp-base.h"
  40.  
  41. // Prefix expressions.
  42.  
  43. class
  44. tree_prefix_expression : public tree_expression
  45. {
  46. public:
  47.  
  48.   enum type
  49.     {
  50.       unknown,
  51.       increment,
  52.       decrement
  53.     };
  54.  
  55.   tree_prefix_expression (int l = -1, int c = -1, type t = unknown)
  56.     : tree_expression (l, c), id (0), etype (t) { }
  57.  
  58.   tree_prefix_expression (tree_identifier *i, int l = -1, int c = -1,
  59.               type t = unknown)
  60.     : tree_expression (l, c), id (i), etype (t) { }
  61.  
  62.   ~tree_prefix_expression (void);
  63.  
  64.   octave_value eval (bool print);
  65.  
  66.   void eval_error (void);
  67.  
  68.   bool is_prefix_expression (void) const
  69.     { return true; }
  70.  
  71.   char *oper (void) const;
  72.  
  73.   tree_identifier *ident (void) { return id; }
  74.  
  75.   void accept (tree_walker& tw);
  76.  
  77. private:
  78.  
  79.   // Currently, a prefix expression can only apply to an identifier.
  80.   tree_identifier *id;
  81.  
  82.   // The type of the expression.
  83.   type etype;
  84. };
  85.  
  86. // Postfix expressions.
  87.  
  88. class
  89. tree_postfix_expression : public tree_expression
  90. {
  91. public:
  92.  
  93.   enum type
  94.     {
  95.       unknown,
  96.       increment,
  97.       decrement
  98.     };
  99.  
  100.   tree_postfix_expression (int l = -1, int c = -1, type t = unknown)
  101.     : tree_expression (l, c), id (0), etype (t) { }
  102.  
  103.   tree_postfix_expression (tree_identifier *i, int l = -1, int c = -1,
  104.                type t = unknown)
  105.     : tree_expression (l, c), id (i), etype (t) { }
  106.  
  107.   ~tree_postfix_expression (void);
  108.  
  109.   octave_value eval (bool print);
  110.  
  111.   void eval_error (void);
  112.  
  113.   char *oper (void) const;
  114.  
  115.   tree_identifier *ident (void) { return id; }
  116.  
  117.   void accept (tree_walker& tw);
  118.  
  119. private:
  120.  
  121.   // Currently, a prefix expression can only apply to an identifier.
  122.   tree_identifier *id;
  123.  
  124.   // The type of the expression.
  125.   type etype;
  126. };
  127.  
  128. // Unary expressions.
  129.  
  130. class
  131. tree_unary_expression : public tree_expression
  132. {
  133. public:
  134.  
  135.   enum type
  136.     {
  137.       unknown,
  138.       not,
  139.       unot,
  140.       uminus,
  141.       hermitian,
  142.       transpose
  143.     };
  144.  
  145.   tree_unary_expression (int l = -1, int c = -1, type t = unknown)
  146.     : tree_expression (l, c), op (0), etype (t) { }
  147.  
  148.   tree_unary_expression (tree_expression *a, int l = -1, int c = -1,
  149.              type t = unknown)
  150.     : tree_expression (l, c), op (a), etype (t) { }
  151.  
  152.   ~tree_unary_expression (void)
  153.     { delete op; }
  154.  
  155.   octave_value eval (bool print);
  156.  
  157.   void eval_error (void);
  158.  
  159.   char *oper (void) const;
  160.  
  161.   bool is_prefix_op (void) { return (etype == not || etype == uminus); }
  162.  
  163.   tree_expression *operand (void) { return op; }
  164.  
  165.   void accept (tree_walker& tw);
  166.  
  167. private:
  168.  
  169.   // The operand for the expression.
  170.   tree_expression *op;
  171.  
  172.   // The type of the expression.
  173.   type etype;
  174. };
  175.  
  176. // Binary expressions.
  177.  
  178. class
  179. tree_binary_expression : public tree_expression
  180. {
  181. public:
  182.  
  183.   enum type
  184.     {
  185.       unknown,
  186.       add,
  187.       subtract,
  188.       multiply,
  189.       el_mul,
  190.       divide,
  191.       el_div,
  192.       leftdiv,
  193.       el_leftdiv,
  194.       power,
  195.       elem_pow,
  196.       cmp_lt,
  197.       cmp_le,
  198.       cmp_eq,
  199.       cmp_ge,
  200.       cmp_gt,
  201.       cmp_ne,
  202.       and,
  203.       or
  204.     };
  205.  
  206.   tree_binary_expression (int l = -1, int c = -1, type t = unknown)
  207.     : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t) { }
  208.  
  209.   tree_binary_expression (tree_expression *a, tree_expression *b,
  210.               int l = -1, int c = -1, type t = unknown)
  211.     : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t) { }
  212.  
  213.   ~tree_binary_expression (void)
  214.     {
  215.       delete op_lhs;
  216.       delete op_rhs;
  217.     }
  218.  
  219.   octave_value eval (bool print);
  220.  
  221.   void eval_error (void);
  222.  
  223.   char *oper (void) const;
  224.  
  225.   tree_expression *lhs (void) { return op_lhs; }
  226.   tree_expression *rhs (void) { return op_rhs; }
  227.  
  228.   void accept (tree_walker& tw);
  229.  
  230. protected:
  231.  
  232.   // The operands for the expression.
  233.   tree_expression *op_lhs;
  234.   tree_expression *op_rhs;
  235.  
  236. private:
  237.  
  238.   // The type of the expression.
  239.   type etype;
  240. };
  241.  
  242. // Boolean expressions.
  243.  
  244. class
  245. tree_boolean_expression : public tree_binary_expression
  246. {
  247. public:
  248.  
  249.   enum type
  250.     {
  251.       unknown,
  252.       and,
  253.       or
  254.     };
  255.  
  256.   tree_boolean_expression (int l = -1, int c = -1, type t)
  257.     : tree_binary_expression (l, c), etype (t) { }
  258.  
  259.   tree_boolean_expression (tree_expression *a, tree_expression *b,
  260.                int l = -1, int c = -1, type t = unknown)
  261.     : tree_binary_expression (a, b, l, c), etype (t) { }
  262.  
  263.   ~tree_boolean_expression (void) { }
  264.  
  265.   octave_value eval (bool print);
  266.  
  267.   char *oper (void) const;
  268.  
  269. private:
  270.  
  271.   // The type of the expression.
  272.   type etype;
  273. };
  274.  
  275. // Simple assignment expressions.
  276.  
  277. class
  278. tree_simple_assignment_expression : public tree_expression
  279. {
  280. public:
  281.  
  282.   tree_simple_assignment_expression (bool plhs = false,
  283.                      bool ans_assign = false,
  284.                      int l = -1, int c = -1)
  285.     : tree_expression (l, c)
  286.       { init (plhs, ans_assign); }
  287.  
  288.   tree_simple_assignment_expression (tree_identifier *i,
  289.                      tree_expression *r,
  290.                      bool plhs = false,
  291.                      bool ans_assign = false,
  292.                      int l = -1, int c = -1);
  293.  
  294.   tree_simple_assignment_expression (tree_indirect_ref *i,
  295.                      tree_expression *r,
  296.                      bool plhs = false,
  297.                      bool ans_assign = false,
  298.                      int l = -1, int c = -1)
  299.     : tree_expression (l, c)
  300.       {
  301.     init (plhs, ans_assign);
  302.     lhs = i;
  303.     rhs = r;
  304.       }
  305.  
  306.   tree_simple_assignment_expression (tree_index_expression *idx_expr,
  307.                      tree_expression *r,
  308.                      bool plhs = false,
  309.                      bool ans_assign = false,
  310.                      int l = -1, int c = -1);
  311.  
  312.   ~tree_simple_assignment_expression (void);
  313.  
  314.   bool left_hand_side_is_identifier_only (void);
  315.  
  316.   tree_identifier *left_hand_side_id (void);
  317.  
  318.   bool is_ans_assign (void)
  319.     { return ans_ass; }
  320.  
  321.   octave_value eval (bool print);
  322.  
  323.   bool is_assignment_expression (void) const
  324.     { return true; }
  325.  
  326.   void eval_error (void);
  327.  
  328.   tree_indirect_ref *left_hand_side (void) { return lhs; }
  329.  
  330.   tree_argument_list *lhs_index (void) { return index; }
  331.  
  332.   tree_expression *right_hand_side (void) { return rhs; }
  333.  
  334.   void accept (tree_walker& tw);
  335.  
  336. private:
  337.  
  338.   // The left hand side of the assignment, as an index expression.  If
  339.   // the assignment is constructed from an index expression, the index
  340.   // expression is split into the its components in the constructor.
  341.   tree_index_expression *lhs_idx_expr;
  342.  
  343.   // The indirect reference (id or structure reference) on the left
  344.   // hand side of the assignemnt.
  345.   tree_indirect_ref *lhs;
  346.  
  347.   // The index of the left hand side of the assignment, if any.
  348.   tree_argument_list *index;
  349.  
  350.   // The right hand side of the assignment.
  351.   tree_expression *rhs;
  352.  
  353.   // True if we should not delete the lhs.
  354.   bool preserve;
  355.  
  356.   // True if this is an assignment to the built-in variable ans.
  357.   bool ans_ass;
  358.  
  359.   void init (bool plhs, bool ans_assign)
  360.     {
  361.       etype = tree_expression::assignment;
  362.       lhs_idx_expr = 0;
  363.       lhs = 0;
  364.       index = 0;
  365.       rhs = 0;
  366.       preserve = plhs;
  367.       ans_ass = ans_assign;
  368.     }
  369. };
  370.  
  371. // Colon expressions.
  372.  
  373. class
  374. tree_colon_expression : public tree_expression
  375. {
  376. public:
  377.  
  378.   tree_colon_expression (int l = -1, int c = -1)
  379.     : tree_expression (l, c, tree_expression::colon),
  380.       op_base (0), op_limit (0), op_increment (0) { }
  381.  
  382.   tree_colon_expression (tree_expression *a, tree_expression *b,
  383.              int l = -1, int c = -1)
  384.     : tree_expression (l, c, tree_expression::colon),
  385.       op_base (a), op_limit (b), op_increment (0) { }
  386.  
  387.   ~tree_colon_expression (void)
  388.     {
  389.       delete op_base;
  390.       delete op_limit;
  391.       delete op_increment;
  392.     }
  393.  
  394.   tree_colon_expression *chain (tree_expression *t);
  395.  
  396.   octave_value eval (bool print);
  397.  
  398.   void eval_error (const char *s);
  399.  
  400.   tree_expression *base (void) { return op_base; }
  401.   tree_expression *limit (void) { return op_limit; }
  402.   tree_expression *increment (void) { return op_increment; }
  403.  
  404.   void accept (tree_walker& tw);
  405.  
  406. private:
  407.  
  408.   // The components of the expression.
  409.   tree_expression *op_base;
  410.   tree_expression *op_limit;
  411.   tree_expression *op_increment;
  412. };
  413.  
  414. #endif
  415.  
  416. /*
  417. ;;; Local Variables: ***
  418. ;;; mode: C++ ***
  419. ;;; End: ***
  420. */
  421.